package com.neusoft.neu.fy25g01.n98.controller;

import com.neusoft.neu.fy25g01.n98.entity.CommonResult;
import com.neusoft.neu.fy25g01.n98.entity.Role;
import com.neusoft.neu.fy25g01.n98.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys/r")
// 允许跨域请求
@CrossOrigin
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PostMapping("/add")
    /**
     * 添加角色业务，如果成功，返回新记录的主键列的值，否则返回-1
     */
    public CommonResult addRole(@RequestBody Role role) {
        return roleService.addRole(role);
    }

    @DeleteMapping("/del/{rid}")
    public int delRole(@PathVariable("rid") int rid) {
        return roleService.delRole(rid);
    }


    /**
     * 修改的前提是：必须提供主键列的值
     *
     * @param role
     * @return
     */
    @PutMapping("/mod/1")
    public int modRole(@RequestBody Role role) {
        int i = -1;
        i = roleService.modRole(role);
        return i;
    }


    @GetMapping("/f/byid/{rid}")
    public Role findById(@PathVariable("rid") int rid) {
        return roleService.findById(rid);
    }

    @GetMapping("/f/byid1/123")
    public List<Role> findById12() {
        return roleService.findAll1();
    }


    @GetMapping("/f/by/null")
    public CommonResult<List<Role>> findAll() {
        return roleService.findAll();
    }
}
